package com.enjoy.mjbaseframe.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.WindowManager;

import com.enjoy.mjbaseframe.R;
import com.enjoy.mjbaseframe.okgo.OkGoLoader;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import me.yokeyword.fragmentation.ISupportFragment;
import me.yokeyword.fragmentation.SupportActivity;
import me.yokeyword.fragmentation.anim.DefaultHorizontalAnimator;
import me.yokeyword.fragmentation.anim.FragmentAnimator;

/**
 * activity基础类
 * Created by Administrator on 2018/3/14.
 */

public abstract class BaseActivity extends SupportActivity {
    private Unbinder binder;//注解

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //透明导航栏
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        if(setLayout() != 0){
            setContentView(setLayout()); //纯粹的Activity基础类
        }else {
            setContentView(R.layout.activity_base);
            loadRootFragment(R.id.fl_container, setFragment());//关联Fragment的Activity
        }
        binder = ButterKnife.bind(this);//注解初始化
        overridePendingTransition(R.anim.fragment_enter, R.anim.fragment_exit);
        init();
    }

    @Override
    protected void onDestroy() {
        if (binder != null) binder.unbind();//解绑
        OkGoLoader.getInstance().clearTags();
        overridePendingTransition(R.anim.fragment_pop_enter, R.anim.fragment_pop_exit);
        super.onDestroy();
    }

    @Override
    public FragmentAnimator onCreateFragmentAnimator() {
        // 设置横向(和安卓4.x动画相同)
        return new DefaultHorizontalAnimator();
    }

    /**
     * 基础activity类
     *
     * @return
     */
    public int setLayout() {
        return 0;
    }

    public void init(){}

    /**
     * 关联Fragment的activity
     * @return
     */
    public ISupportFragment setFragment() {
        return null;
    }
}
